﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockFinder.Model;
using System.Windows.Forms;

namespace StockFinder.UI
{
    public class TradingSystemParametersScreenBuilder
    {
        public GroupBox Build(TradingSystemParameters parameters)
        {
            GroupBox groupBox = new GroupBox();
            TableLayoutPanel tableLayoutPanel = new TableLayoutPanel();

            //get the properties for this system parameters
            var properties = parameters.GetType().GetProperties();

            //set up table columns
            tableLayoutPanel.ColumnCount = 2;
            tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));                                    

            //set up table rows
            tableLayoutPanel.RowCount = properties.Length;
            float rowHeight = 100 / properties.Length;
            for (int i = 0; i < properties.Length; i++)
            {
                tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(
                    System.Windows.Forms.SizeType.Percent, rowHeight));
            }            
           

            foreach (var item in properties)
            {                                
                //add info label
                tableLayoutPanel.Controls.Add(new Label { Text = item.Name },0,0);

                var itemValue = item.GetValue(parameters, null);

                if (itemValue is decimal)
                {

                }
                else if (itemValue is int)
                {

                }
                else
                {
                    throw new Exception("Unrecognised system parameter type");
                }
            }

            return groupBox;
        }
    }
}
